function [invA] = InverseOfBlockDiagonalMatrix(A)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here

% Check whether A is block diagonal

% Determine the size of the blocks

invA = zeros(size(A));

blockSize = sum(A(:,1)~=0);
numblocks = size(A,1)/blockSize;

if blockSize == 1; % Easy case: The matrix is diagonal, take inverse of elements

    for block = 1:numblocks
        invA(block,block) = 1/A(block,block);
    end
    
else % Case 2, do it blocks

    for block = 1:numblocks
        a=1+blockSize*(block-1):blockSize*block;
        invA(a,a) = inv(A(a,a));
    end
    
end


end

